import { message } from 'antd';
import { getAppList,getFunctionList, addAppAuth, updateAuth, deleteAuth, 
openStatus, closeStatus, getFunctionInfoList, deleteAuthInfo } from '../services';

export default{
  namespace: 'appManageModel',

  state:{
    appList: [],
    appTotal: 0,
  },

  effects:{
    *getAppList({payload},{put,call}){
      const res = yield call(getAppList,payload);
      const { code, data ,message:errMsg } = res;
      if(code === 0){
        const { dataList, total } = data;
        yield put({
          type: 'updateModel',
          payload:{
            appList: dataList,
            appTotal: total
          }
        })
      }else{
        message.error(errMsg);
      }
    },

    *getFunctionList({payload},{put,call}){
      return yield call(getFunctionList,payload)
    },

    *addAppAuth({payload},{put,call}){
      return yield call(addAppAuth,payload);
    },

    *updateAuth({payload},{put,call}){
      return yield call(updateAuth,payload);
    },

    *deleteAuth({payload},{put,call}){
      return yield call(deleteAuth,payload);
    },

    *openStatus({payload},{put,call}){
      return yield call(openStatus,payload);
    },

    *closeStatus({payload},{put,call}){
      return yield call(closeStatus,payload);
    },

    *getFunctionInfoList({payload},{put,call}){
      return yield call(getFunctionInfoList,payload);
    },

    *deleteAuthInfo({payload},{put,call}){
      return yield call(deleteAuthInfo,payload);
    }
  },

  reducers:{
    updateModel:(state,{payload}) =>({
      ...state,
      ...payload
    })
  }
}



